home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / helpful.zip / elf < prev    next >
Text File  |  1995-08-21  |  34KB  |  859 lines

  1.   The Linux ELF HOWTO
  2.   Daniel Barlow <daniel.barlow@sjc.ox.ac.uk>
  3.   v1.03, August 1995
  4.  
  5.   This document describes how to migrate your Linux system to compile
  6.   and run programs in the ELF binary format.  It falls into three con-
  7.   ceptual parts: (1) What ELF is, and why/whether you should upgrade,
  8.   (2) How to upgrade to ELF-capability, and (3) what you can do then.
  9.  
  10.   1.  What is ELF?  An introduction
  11.  
  12.   ELF (Executable and Linking Format) is a binary format originally
  13.   developed by USL (UNIX System Laboratories) and currently used in
  14.   Solaris and System V Release 4.  Because of its increased flexibility
  15.   over the older a.out format that Linux currently uses, the GCC and C
  16.   library developers decided last year to move to using ELF as the Linux
  17.   standard binary format also.
  18.  
  19.   This `increased flexibility' manifests as essentially two benefits to
  20.   the average applications progammer:
  21.  
  22.  
  23.   o  It is much simpler to make shared libraries with ELF.  Typically,
  24.      just compile all the object files with -fPIC, then link with a
  25.      command like
  26.  
  27.  
  28.  
  29.         gcc -shared -Wl,-soname,libfoo.so.y -o libfoo.so.y.x *.o
  30.  
  31.  
  32.  
  33.  
  34.  
  35.   Now that may look complex, but it's far simpler than the method for
  36.   a.out shared libraries, which involves reserving space for all the
  37.   data you think that the library is likely to require in future, and
  38.   registering that address space with a third party (it's described in a
  39.   document over 20 pages long --- look at
  40.   <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/src/tools-2.16.tar.gz>
  41.   for details).
  42.  
  43.   o  It makes dynamic loading (ie programs which can load modules at
  44.      runtime) much simpler.  This is used by Perl 5, Python, and the
  45.      ongoing port of Java to Linux, among other things.  Other
  46.      suggestions for dynamic loading have included super-fast MUDs,
  47.      where extra code could be compiled and linked into the running
  48.      executable without having to stop and restart the program.
  49.  
  50.  
  51.   Against this it must be weighed that ELF is reputed to be possibly a
  52.   bit slower.  The figures that get bandied around are between 2% and
  53.   5%, though as far as I know nobody has done any proper testing.  If
  54.   you do know of any comparative tests, please let me know too.
  55.  
  56.   The slowdown comes from the fact the ELF library code must be position
  57.   independent (this is what the -fPIC above is for) and so a register
  58.   must be devoted to holding offsets.  That's one less for holding
  59.   variables in, and the 80x86 has a paucity of general-purpose registers
  60.   anyway.
  61.  
  62.  
  63.   1.1.  What ELF isn't
  64.  
  65.   There are a number of common misconceptions about what ELF will do for
  66.   your system:
  67.      It's not a way to run SVR4 or Solaris programs
  68.         Although it's the same binary `container' as SVR4 systems use,
  69.         that doesn't mean that SVR4 programs suddenly become runnable on
  70.         Linux.  It's analogous to a disk format --- you can keep Linux
  71.         programs on MSDOS or Minix-format disks, and vice versa, but
  72.         that doesn't mean that these systems become able to run each
  73.         others' programs.
  74.  
  75.         It is theoretically possible to run applications for other x86
  76.         Unices under Linux, but following the instructions in this HOWTO
  77.         will not have that effect.  Start by looking at the iBCS kernel
  78.         module (somewhere on tsx-11.mit.edu) and see if it fits your
  79.         needs.
  80.  
  81.  
  82.      It's not intrinsically smaller or faster
  83.         You may well end up with smaller binaries anyway, though, as you
  84.         can more easily create shared libraries of common code between
  85.         many programs.  In general, if you use the same compiler options
  86.         and your binaries come out smaller than they did with a.out,
  87.         it's more likely to be fluke or a different compiler version.
  88.         As for `faster', I'd be surprised.  Speed increases could turn
  89.         up if your binaries are smaller, due to less swapping or larger
  90.         functional areas fitting in cache.
  91.  
  92.  
  93.      It doesn't require that you replace every binary on your system
  94.         At the end of this procedure you have a system capable of
  95.         compiling and running both ELF and a.out programs.  New programs
  96.         will by default be compiled in ELF, though this can be
  97.         overridden with a command-line switch.  There is admittedly a
  98.         memory penalty for running a mixed ELF/a.out system --- if you
  99.         have both breeds of program running at once you also have two
  100.         copies of the C library in core, and so on.  I've had reports
  101.         that the speed difference from this is undetectable in normal
  102.         use on a 6Mb system though (I certainly haven't noticed much in
  103.         8Mb), so it's hardly pressing.  You lose far more memory every
  104.         day by running bloated programs like Emacs and static
  105.         Mosaic/Netscape binaries :-)
  106.  
  107.  
  108.      It's nothing to do with Tolkien, Pratchett, Keebler, or general
  109.         mythology" Or at least, not in this context.  'Nuff said.
  110.  
  111.  
  112.  
  113.   1.2.  Why you should(n't) convert to ELF
  114.  
  115.   There are essentially two reasons to upgrade your system to compile
  116.   and run ELF programs: the first is the increased flexibility in
  117.   programming referred to above, and the second is that, due to the
  118.   first, everyone else will be too.  Future releases of the C library
  119.   and GCC will only be compiled for ELF, and other developers are
  120.   expected to move ELFwards too.
  121.  
  122.   Pleasingly for the purposes of symmetry, there are also two reasons
  123.   not to convert at this time.  The first is that things are still
  124.   changing, some packages (including the `stable' 1.2 kernel series)
  125.   require patches to be made before they will compile in ELF, and there
  126.   may be residual bugs; one could make a strong case for waiting until
  127.   Linus himself has converted, for example.
  128.  
  129.   The second is that although the installation described here is a
  130.   fairly small job in itself (it can be completed in well under an hour,
  131.   excepting the time taken to download the new software), an error at
  132.   almost any stage of it will probably leave you with an unbootable
  133.   system.  If you are not comfortable with upgrading shared libraries
  134.   and the commands ldconfig and ldd mean nothing to you, you may want to
  135.   obtain or wait for a new Linux distribution in ELF, and backup,
  136.   reinstall and selectively restore your system using it.  Then again
  137.   (and especially if the system is not mission-critical) you may want to
  138.   go through it anyway and look on it as a learning experience.
  139.  
  140.   Still with us?
  141.  
  142.  
  143.   2.  Installation
  144.  
  145.   2.1.  Background
  146.  
  147.   The aim of this conversion is to leave you with a system which can
  148.   build and run both a.out and ELF programs, with each type of program
  149.   being able to find its appropriate breed of shared libraries.  This
  150.   obviously requires a bit more intelligence in the library search
  151.   strategy than the simple `look in /lib, /usr/lib and anywhere else
  152.   that the program was compiled to search' strategy that some other
  153.   systems can get away with.
  154.  
  155.   The beastie responsible for searching out libraries in linux is
  156.   /lib/ld.so.  The compiler and linker do not encode absolute library
  157.   pathnames into the programs they output; instead they put the library
  158.   name and the absolute path to ld.so in, and leave ld.so to match the
  159.   library name to the appropriate place at runtime.  This has one very
  160.   important effect --- it means that the libraries that a program uses
  161.   can be moved to other directories without recompiling the program,
  162.   provided that ld.so is told to search the new directory.  This is
  163.   essential for the directory swapping operation that follows.
  164.  
  165.   The corollary of the above, of course, is that any attempt to delete
  166.   or move ld.so will cause every dynamically linked program on the
  167.   system to stop working.  This is generally regarded as a Bad Thing.
  168.  
  169.   For ELF binaries, an alternate dynamic loader is provided.  This is
  170.    /lib/ld-linux.so.1, and does exactly the same thing as ld.so, but for
  171.   ELF programs.  ld-linux.so.1 uses the same support files and programs
  172.   (ldd, ldconfig, and /etc/ld.so.conf) as the a.out loader ld.so does.
  173.  
  174.   The basic plan, then, is that ELF development things (compilers,
  175.   include files and libraries) go into /usr/{bin,lib,include} where your
  176.   a.out ones currently are, and the a.out things will be moved into
  177.   /usr/i486-linuxaout/{bin, lib, include}.  /etc/ld.so.conf lists all
  178.   the places on the system where libraries are expected to be found, and
  179.   ldconfig is intelligent enough to distinguish between ELF and a.out
  180.   variants.  There are a couple of exceptions to the library placement,
  181.   though; see the Caveats section below.
  182.  
  183.  
  184.   2.2.  Before you start --- Notes and Caveats
  185.  
  186.  
  187.   o  You will need to be running a post-1.1.52 kernel with ELF binary
  188.      format support.  Note that kernel versions 1.3.0 to 1.3.2 inclusive
  189.      had an ELF-related bug.  If you're running the development 1.3
  190.      kernel series, make sure you stay current!  1.3.3 is fine, as is
  191.      1.2.10 (the latest stable kernel at time of writing).
  192.  
  193.   o  You are recommended to prepare or acquire a linux boot/root disk,
  194.      such as a Slackware rescue disk.  You probably won't need it, but
  195.      if you do and you don't have one, you'll kick yourself.  In a
  196.      similar `prevention is better than cure' vein, statically linked
  197.      copies of mv, ln, and maybe other file manipulation commands
  198.      (though in fact I think you can do everything else you actually
  199.      need to with shell builtins) may help you out of any awkward
  200.      situations you could end up in.
  201.  
  202.   o  Extra care is needed if you have /usr or /usr/lib on a separate
  203.      partition from /.  You will need to check the libraries that your
  204.      programs in /bin and /sbin use, and put those libraries somewhere
  205.      on the root partition, say in /lib-aout.  I'll come back to this at
  206.      the appropriate spot.
  207.  
  208.   o  If you have been following the ELF development, you may have ELF
  209.      libraries in /lib/elf (usually libc.so.4 and co).  Applications
  210.      that you built using these should be rebuilt, then the directory
  211.      removed.  There is no need for a /lib/elf directory!  It was used
  212.      for a time during ELF development, but how it ended up as a
  213.      standard directory in Slackware installs, who knows?
  214.  
  215.   o  Some old programs don't use ld.so, so any libraries that they
  216.      depend on cannot be moved.  There may or may not be a problem here.
  217.      Use ldd to determine which these libraries are.  If the program
  218.      depends only on libc.so.4 and/or libm.so.4, there is no problem, as
  219.      these libraries continue to reside in /lib.  If it depends on X in
  220.      any way, shape, or form, you're also safe: to be old enough not to
  221.      use ld.so it would have to have been compiled with a pretty old
  222.      version of the X libraries, and both the major version number and
  223.      directory placement of the X libraries has changed since then.
  224.  
  225.      If you do have a clash between an a.out library that cannot be
  226.      moved and an ELF library with the same major version that wants to
  227.      install over the top of it, you'll have to put the ELF library
  228.      somewhere else and add the other directory to /etc/ld.so.conf.
  229.  
  230.      If your system is old enough that you still have shared libraries
  231.      with dates in the filenames then you're obviously a Linux God(tm)
  232.      and should be advising me on the appropriate course of action at
  233.      this point :-)  Answers to the address in the title of this HOWTO.
  234.  
  235.   o  Most Linux installations these days have converged on the `FSSTND'
  236.      standard file system, but doubtless there are still installed
  237.      systems that haven't.  If you see references to /sbin/something and
  238.      you don't have a /sbin directory, you'll probably find the program
  239.      referred to in /bin or /etc/.
  240.  
  241.  
  242.   2.3.  You will need ...
  243.  
  244.   The following packages are available from
  245.   <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/> and
  246.   <ftp://sunsite.unc.edu/pub/Linux/GCC/>.  Both sites are widely
  247.   mirrored; please take the time to look up your nearest mirror site and
  248.   use that instead of the master sites where possible.  It's faster for
  249.   both you and everyone else.
  250.  
  251.   These packages (either the listed version or a later one) are
  252.   required.  Also download and read through the release notes for each
  253.   of them: these are the files named release.packagename.  This applies
  254.   especially if you get newer versions than are listed here, as
  255.   procedures may have changed.
  256.  
  257.  
  258.   o  ld.so-1.7.3.tar.gz --- the new dynamic linker
  259.  
  260.   o  libc-5.0.9.bin.tar.gz --- the ELF shared images for the C library
  261.      and its friends (m (maths), termcap, gdbm, and so on), plus the
  262.      corresponding static libraries and the include files needed to
  263.      compile programs with them.
  264.  
  265.   o  gcc-2.7.0.bin.tar.gz --- the ELF C compiler.  Also includes an
  266.      a.out C compiler which understands the new directory layout.
  267.  
  268.   o  binutils-2.5.2l.17.bin.tar.gz --- the GNU binary utilities patched
  269.      for Linux.  These are programs such as gas, ld, strings and so on,
  270.      most of which are required to make the C compiler go.  Note that
  271.      you can also use binutils-2.5.2l.20.bin.tar.gz, if it's arrived in
  272.      your part of the world.
  273.  
  274.  
  275.   2.4.  Rearranging your filesystem
  276.  
  277.   Sooo...  Note that in all that follows, when I say `remove' I
  278.   naturally mean `backup then remove' :-).  Also, these instructions
  279.   directly apply only to people who haven't yet messed with ELF ---
  280.   those who have are expected to have the necessary nous to adapt as
  281.   appropriate.  Let's go!
  282.  
  283.  
  284.   1. If you have separate / and /usr partitions, some caution is
  285.      required here.  You must check each program that is run at startup
  286.      before /usr is mounted, or run in other situations where /usr is
  287.      unavailable, and put all the libraries required by it in /lib-aout.
  288.  
  289.      This is actually less tedious than it sounds.  Simply run
  290.  
  291.  
  292.  
  293.        $ ldd /sbin/* /bin/* /etc/* >/tmp/list.txt
  294.  
  295.  
  296.  
  297.  
  298.  
  299.   and then look through /tmp/list.txt , ignoring all the errors from
  300.   non-executable files, and noting which libraries appear.  These are
  301.   the libraries which you will need on the root partition.  Keep this
  302.   list.
  303.  
  304.   2. Make the new directories that you will move a.out things to
  305.  
  306.  
  307.        ______________________________________________________________________
  308.        mkdir -p /usr/i486-linuxaout/bin
  309.        mkdir -p /usr/i486-linuxaout/include
  310.        mkdir -p /usr/i486-linuxaout/lib
  311.        mkdir /lib-aout
  312.        ______________________________________________________________________
  313.  
  314.  
  315.  
  316.  
  317.  
  318.   3. Untar the dynamic linker package ld.so-1.7.3 in the directory you
  319.      usually put source code, then read through the
  320.      ld.so-1.7.3/instldso.sh script just unpacked.  If you have a really
  321.      standard system, run it by doing sh instldso.sh, but if you have
  322.      anything at all unusual then do the install by hand instead.
  323.      `Anything at all unusual' includes
  324.  
  325.   o  using zsh as a shell (some versions of zsh define $VERSION, which
  326.      seems to confuse instldso.sh)
  327.  
  328.   o  having symlinks from /lib/elf to /lib (which you shouldn't need,
  329.      but you may have valid reasons for if you have been following the
  330.      ELF development)
  331.      Edit /etc/ld.so.conf to add the new directory
  332.      /usr/i486-linuxaout/lib (and /lib-aout if you're going to need
  333.      one).  Then rerun /sbin/ldconfig -v to check that it is picking up
  334.      the new directories.
  335.  
  336.   4. Move all your a.out libraries in /usr/*/lib to
  337.      /usr/i486-linuxaout/lib.  If /usr is not on the root partition,
  338.      refer now to the list you made of libraries that are needed in
  339.      single-user mode, and move them from /lib to /lib-aout.  After
  340.      doing that, or if you didn't need to do that, move all remaining
  341.      libraries in /lib to /usr/i486-linuxaout/lib.  Don't move, delete
  342.      or do anything with /lib/ld.so!
  343.  
  344.      For people with only the one partition, the following series of
  345.      commands are pretty well what you need to do.
  346.  
  347.  
  348.  
  349.        ______________________________________________________________________
  350.        cd /lib
  351.        mv *.o *.a *.sa /usr/i486-linuxaout/lib
  352.        mv libfoo.so* libbar.so* libmumble.so*  /usr/i486-linuxaout/lib
  353.        cd /usr/lib
  354.        mv *.o *.a *.so* *.sa /usr/i486-linuxaout/lib
  355.        cd /usr/X11R6/lib
  356.        mv *.o *.a *.so* *.sa /usr/i486-linuxaout/lib
  357.        cd /usr/local/lib
  358.        mv *.o *.a *.so* *.sa /usr/i486-linuxaout/lib
  359.        ______________________________________________________________________
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.   If you actually typed in the third line of that without reading it
  367.   first, you'll observe that it didn't do anything.  What you should be
  368.   attempting to do there is move all files matching *.so* except for
  369.   libc.so*, libm.so* and libdl.so* to /usr/i486-linuxaout/lib.  I can't
  370.   advise more specifically than that as I don't know what libraries you
  371.   have in /lib
  372.  
  373.   Do not pass this stage until you have removed all libraries and object
  374.   (*.o) files from each of the above directories, except for libc.so*,
  375.   libm.so* and libdl.so* in /lib, which you need to keep so that aged
  376.   programs continue to work, and ld.so in /lib, which you still need for
  377.   anything to work.  Now run ldconfig again.
  378.  
  379.  
  380.   5. Remove the directory /usr/lib/ldscripts if it's there.
  381.  
  382.   6. Remove any copies of ld and as (except for ld86 and as86) that you
  383.      can find in /usr/bin.
  384.  
  385.   7. Some versions of GNU tar appear to have problems dealing with
  386.      symbolically linked files.  Before installing the libc images you
  387.      might want to go through /usr/include and remove some parts.
  388.  
  389.      This is icky.  Many packages (such as ncurses) are installed into
  390.      /usr/include by distribution maintainers and are not supplied with
  391.      the C library.  Backup the /usr/include tree, use tar tzf to see
  392.      what's in the file before untarring it, and delete the directories
  393.      that it actually fills.  Then untar the libc-5.0.9.bin.tar.gz
  394.      package from root.
  395.  
  396.  
  397.   8. Install the binutils package.  tar -xvzf
  398.      binutils-2.6.2.l17.bin.tar.gz -C /  is one perfectly good way to do
  399.      this.
  400.  
  401.   9. You have now installed everything you need to run ELF executables.
  402.      Medical experts recommend that VDU workers take regular breaks away
  403.      from the screen; this would be an opportune moment.  Don't forget
  404.      what you were doing, though; depending on the version of gcc you
  405.      were previously using, you may have left yourself unable to compile
  406.      programs in a.out until you unpack the new gcc.
  407.  
  408.   10.
  409.      Backup and remove everything in /usr/lib/gcc-lib/{i486-linux,
  410.      i486-linuxelf, i486-linuxaout}/ Then install the gcc package, again
  411.      by untarring from root.
  412.  
  413.   11.
  414.      Some programs (notably various X programs) use /lib/cpp, which
  415.      under Linux is generally a link to /usr/lib/gcc-
  416.      lib/i486-linux/version/cpp.  As the preceding step wiped out
  417.      whatever version of cpp it was pointing to, you'll need to recreate
  418.      the link:
  419.  
  420.  
  421.  
  422.        $ cd /lib
  423.        $ ln -s /usr/lib/gcc-lib/i486-linux/2.7.0/cpp .
  424.  
  425.  
  426.  
  427.  
  428.  
  429.    Done!  Simple tests that you can try are
  430.  
  431.  
  432.  
  433.        ______________________________________________________________________
  434.        $ gcc -v
  435.        Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.0/specs
  436.        gcc version 2.7.0
  437.        $ gcc -v -b i486-linuxaout
  438.        Reading specs from /usr/lib/gcc-lib/i486-linuxaout/2.7.0/specs
  439.        gcc version 2.7.0
  440.        $ ld -V
  441.        ld version cygnus/linux-2.5.2l.14 (with BFD cygnus/linux-2.5.2l.11)
  442.          Supported emulations:
  443.           elf_i386
  444.           i386linux
  445.           i386coff
  446.        ______________________________________________________________________
  447.  
  448.  
  449.  
  450.  
  451.   followed of course by the traditional ``Hello, world'' program.  Try
  452.   it with gcc and with gcc -b i486-linuxaout to check that both the
  453.   a.out and ELF compilers are set up corectly.
  454.  
  455.  
  456.   2.5.  Common errors
  457.  
  458.   I'm soliciting reports of people's problems for this section.  Your
  459.   anonymity will be preserved if you so request :-)
  460.  
  461.  
  462.  
  463.       no such file or directory: /usr/bin/gcc
  464.         that the ELF dynamic loader /lib/ld-linux.so.1 is not installed,
  465.         or is unreadable for some reason.  You should have installed it
  466.         at around step 3 of the previous section.
  467.  
  468.  
  469.       not a ZMAGIC file, skipping
  470.         from ldconfig.  You have an old version of the ld.so package, so
  471.         get a recent one.  Again, see step 3 of the previous section.
  472.  
  473.  
  474.       bad address
  475.         on attempting to run anything ELF.  You're using kernel 1.3.x,
  476.         where x<3.  Upgrade to 1.3.3 or downgrade to 1.2.something
  477.  
  478.  
  479.       _setutent: Can't open utmp file
  480.         You didn't read the libc release notes.  In accordance with
  481.         version 1.2 of the FSSTND, utmp and wtmp have moved again, and
  482.         should now be located in /var/run and /var/log respectively.
  483.         Recommended practice is to add symlinks from their old locations
  484.         so that your older programs will also find them.  Don't forget
  485.         to check your startup scripts (/etc/bcheckrc, for example) to
  486.         make sure you're not deleting things you shouldn't at startup.
  487.  
  488.  
  489.       gcc: installation problem, cannot exec something: No such file or
  490.         directory
  491.         when attempting to do a.out compilations (something is usually
  492.         one of cpp or cc1).  Either it's right, or alternatively you
  493.         typed
  494.  
  495.  
  496.  
  497.           $ gcc -b -i486-linuxaout
  498.  
  499.  
  500.  
  501.  
  502.      when you should have typed
  503.  
  504.  
  505.  
  506.           $ gcc -b i486-linuxaout
  507.  
  508.  
  509.  
  510.  
  511.      Note that the `i486' does not start with a dash.
  512.  
  513.  
  514.  
  515.   3.  Building programs in ELF
  516.  
  517.   3.1.  Ordinary programs
  518.  
  519.   To build a program in ELF, use gcc as always.  To build in a.out, use
  520.   gcc -b i486-linuxaout .
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.   ______________________________________________________________________
  530.   $ cat >hello.c
  531.   main() { printf("hello, world\n"); }
  532.   ^D
  533.   $ gcc -o hello hello.c
  534.   $ file hello
  535.   hello: ELF 32-bit LSB executable i386 (386 and up) Version 1
  536.   $ ./hello
  537.   hello, world
  538.   ______________________________________________________________________
  539.  
  540.  
  541.  
  542.  
  543.   This is perhaps an appropriate time to answer the question ``if a.out
  544.   compilers default to producing a program called a.out, what name does
  545.   an ELF compiler give its output?''.  Still a.out, is the answer.
  546.   Boring boring boring ...  :-)
  547.  
  548.  
  549.   3.2.  Building libraries
  550.  
  551.   To build libfoo.so as a shared library, the basic steps look like
  552.   this:
  553.  
  554.  
  555.  
  556.        ______________________________________________________________________
  557.        $ gcc -fPIC -c *.c
  558.        $ gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o
  559.        $ ln -s libfoo.so.1.0 libfoo.so.1
  560.        $ ln -s libfoo.so.1 libfoo.so
  561.        $ export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
  562.        ______________________________________________________________________
  563.  
  564.  
  565.  
  566.  
  567.   This will generate a shared library called libfoo.so.1.0, and the
  568.   appropriate links for ld (libfoo.so) and the dynamic linker
  569.   (libfoo.so.1) to find it.  To test, we add the current directory to
  570.   LD_LIBRARY_PATH.
  571.  
  572.   When you're happpy that the library works, you'll have to move it to,
  573.   say, /usr/local/lib, and recreate the appropriate links.  Note that
  574.   the libfoo.so link should point to libfoo.so.1, so it doesn't need
  575.   updating on every minor version number change.  The link from
  576.   libfoo.so.1 to libfoo.so.1.0 is kept up to date by ldconfig, which on
  577.   most systems is run as part of the boot process.
  578.  
  579.  
  580.  
  581.        ______________________________________________________________________
  582.        $ su
  583.        # cp libfoo.so.1.0 /usr/local/lib
  584.        # /sbin/ldconfig
  585.        # ( cd /usr/local/lib ; ln -s libfoo.so.1 libfoo.so )
  586.        ______________________________________________________________________
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.   3.3.  Programs with dynamic loading
  596.  
  597.   These are covered extensively in H J Lu's ELF programming document,
  598.   and the dlopen(3) manual page, which can be found in the ld.so
  599.   package.  Here's a nice simple example though: link it with -ldl
  600.  
  601.  
  602.  
  603.        ______________________________________________________________________
  604.        #include <dlfcn.h>
  605.        #include <stdio.h>
  606.  
  607.        main()
  608.        {
  609.          void *libc;
  610.          void (*printf_call)();
  611.  
  612.          if(libc=dlopen("/lib/libc.so.5",RTLD_LAZY))
  613.          {
  614.            printf_call=dlsym(libc,"printf");
  615.            (*printf_call)("hello, world\n");
  616.          }
  617.  
  618.        }
  619.        ______________________________________________________________________
  620.  
  621.  
  622.  
  623.  
  624.  
  625.   3.4.  Debugging
  626.  
  627.   Your existing copy of gdb will most likely work unchanged with ELF
  628.   programs.  The new version in the GCC directory on tsx-11 is reported
  629.   to be better at debugging programs that use dynamic loading and to
  630.   understand ELF core dumps.
  631.  
  632.   At the time of writing, a patch to the kernel is necessary before ELF
  633.   programs will generate core dumps anyway, so it's perhaps a little
  634.   academic.
  635.  
  636.  
  637.   4.  Patches and binaries
  638.  
  639.   At this point in the proceedings, you can, if you like, stop.  You
  640.   have installed everything necessary to compile and run ELF programs.
  641.  
  642.   You may wish to rebuild some programs in ELF, either for purposes of
  643.   `neatness' or to minimise memory usage.  For most end-user
  644.   applications, this is pretty simple; some packages however do assume
  645.   too much about the systems they run on, and may fail due to one or
  646.   more of:
  647.  
  648.   o  Different underscore conventions in the assembler: in an a.out
  649.      executable, external labels get _ prefixed to them; in an ELF
  650.      executable, they don't.  This makes no difference until you start
  651.      integrating hand-written assembler: all the labels of the form _foo
  652.      must be translated to foo, or (if you want to be portable about it)
  653.      to EXTERNAL(foo) where EXTERNAL is some macro which returns either
  654.      its argument (if __ELF__ is defined) or _ concatenated with its
  655.      argument if not.
  656.  
  657.   o  Differences in libc 5 from libc 4.  The interface to the locale
  658.      support has changed, for one.
  659.  
  660.  
  661.   o  The application or build process depends on knowledge of the binary
  662.      format used --- emacs, for example, dumps its memory image to disk
  663.      in executable format, so obviously needs to know what format your
  664.      executables are in.
  665.  
  666.   o  The application consists of or includes shared libraries (X11 is
  667.      the obvious example).  These will obviously need changes to
  668.      accomodate the different method of shared library creation in ELF.
  669.  
  670.   Anyway, here are two lists: the first is of programs that needed
  671.   changing for ELF where the changes have been made (ie that you will
  672.   need new versions of to compile as ELF), and the second is of programs
  673.   that still need third-party patches of some kind.
  674.  
  675.  
  676.   4.1.  Upgrade:
  677.  
  678.  
  679.   o  Dosemu.  Modulo the three or four cuurrent dosemu development trees
  680.      (don't ask, just join the linux-msdos mailing list), dosemu runs
  681.      with ELF.  You'll need to monkey with the Makefile.  Current
  682.      versions of dosemu are available from
  683.      <ftp://tsx-11.mit.edu/pub/linux/ALPHA/dosemu/>
  684.  
  685.   o  Emacs.  Emacs has a rather odd build procedure that involves
  686.      running a minimal version of itself, loading in all the useful bits
  687.      as lisp, then dumping its memory image back to disk as an
  688.      executable file.  (FSF) Emacs 19.29 and XEmacs 19.12 (formerly
  689.      Lucid Emacs) can both detect whether you are compiling as ELF and
  690.      Do The Right Thing automatically.
  691.  
  692.   o  MAKEDEV.  In some incarnations, this utility removes existing
  693.      entries for devices before recreating them.  This is Bad News if it
  694.      happens to touch /dev/zero, as said device is necessary to the
  695.      operation of all ELF programs.  See the util-linux package(q.v.)
  696.      for a fixed version.
  697.  
  698.   o  perl 5.001.  Perl 5.001 plus the ``official unofficial'' patches a-
  699.      e will compile unchanged on an ELF system, complete with dynamic
  700.      loading.  The patches are available from ftp.metronet.com or
  701.      ftp.wpi.edu
  702.  
  703.   o  The cal program in util-linux 2.2 doesn't work.  Upgrade to version
  704.      2.4 <ftp://tsx-11.mit.edu/pub/linux/packages/utils> or later.
  705.  
  706.   o  XFree86.  XFree86 3.1.2 comes in both a.out and ELF formats.  ftp
  707.      to ftp.xfree86.org, read the `too many users' message that you are
  708.      almost guaranteed to get, and pick the closest mirror site network-
  709.      wise to you.
  710.  
  711.      I confess to not having actually tried this yet.  At time of
  712.      writing, it's only been out for one day ;-)
  713.  
  714.  
  715.   4.2.  Patch
  716.  
  717.  
  718.   o  e2fsutils.  The Utilities for the Second Extended File System need
  719.      a patch from
  720.      <ftp://ftp.ibp.fr/pub/linux/ELF/patches/e2fsprogs-0.5b.elf.diff.gz>
  721.      to compile correctly as a shared library.  Remy Card says ``This is
  722.      the ELF patch which will probably be included in the next release
  723.      of e2fsck and co''
  724.  
  725.   o  file.  This works anyway, but can be improved:
  726.      <http://sable.ox.ac.uk/~jo95004/patches/file.diff> adds support for
  727.      identifying stripped and mixed-endian ELF binaries.
  728.  
  729.   o  The Kernel.  As from at least 1.3.8, the development 1.3 series
  730.      have a make config option to build using ELF tools.  If you are
  731.      using the 1.2 series, you have two options:
  732.  
  733.  
  734.      1. Patch the Makefile slightly to use the a.out compiler.  Just
  735.         change the CC and LD definitions to be
  736.  
  737.  
  738.  
  739.           ___________________________________________________________________
  740.           LD      =ld -m i386linux
  741.           CC      =gcc -b i486-linuxaout -D__KERNEL__ -I$(TOPDIR)/include
  742.           ___________________________________________________________________
  743.  
  744.  
  745.  
  746.  
  747.  
  748.      Alternatively,
  749.  
  750.      2. Apply H J Lu's patch which allows compiling the kernel in ELF
  751.         (and also adds the ability to do ELF core dumps).
  752.  
  753.  
  754.      Let me reiterate that neither of these is necessary for the 1.3
  755.      series.
  756.  
  757.   o  ps (procps-0.97) The psupdate program needs a patch to work if you
  758.      have compiled the kernel as ELF.  It's available in
  759.      <linux.nrao.edu:/pub/people/juphoff/procps>, both as a patch to
  760.      vanilla 0.97 and as an entire tar-file.  A new version of procps is
  761.      expected to be released soon with this patch in place, so if you
  762.      can find procps 0.98 by the time you read this, this patch will
  763.      probably be obsolete.
  764.  
  765.   o  SVGATextMode requires a single simple adjustment.  Cut out the diff
  766.      below and apply it, or else make the patch by hand.
  767.  
  768.  
  769.  
  770.        ______________________________________________________________________
  771.        --- SVGATextMode-0.7.orig/XFREE/os-support/assyntax.h   Sun Feb 26 18:58:15 1995
  772.        +++ SVGATextMode-0.7/XFREE/os-support/assyntax.h        Thu Mar 30 07:52:03 1995
  773.        @@ -211,7 +211,7 @@
  774.         #endif /* ACK_ASSEMBLER */
  775.  
  776.  
  777.        -#if (defined(SYSV) || defined(SVR4)) && !defined(ACK_ASSEMBLER)
  778.        +#if (defined (__ELF__) || defined(SYSV) || defined(SVR4)) && !defined(ACK_ASSEMBLER)
  779.         #define GLNAME(a)       a
  780.         #else
  781.         #define GLNAME(a)       CONCAT(_,a)
  782.        ______________________________________________________________________
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.   5.  Further information
  790.  
  791.  
  792.  
  793.   o  The linux-gcc mailing list is really the best place to see what's
  794.      happening, usually without even posting to it.  Remember, it's not
  795.      Usenet, so keep the questions down unless you're actually
  796.      developing.  For instructions on joining the mailing list, mail a
  797.      message containing the word help to majordomo@vger.rutgers.edu
  798.  
  799.   o  There's a certain amount of information about what the linux-gcc
  800.      list is doing at my ELF web page
  801.      <http://sable.ox.ac.uk/~jo95004/elf.html>, when I remember to
  802.      update it.  Archives of the list itself are at
  803.      <http://homer.ncm.com/>.
  804.  
  805.   o  See also Bobby Shmit's ELF upgrade experience
  806.      <http://www.intac.com/~cully/elf.html> web page.
  807.  
  808.   o  The GCC-FAQ <ftp://sunsite.unc.edu/pub/Linux/docs/faqs/GCC-
  809.      FAQ.html> contains much general development information and some
  810.      more technical ELF details.
  811.  
  812.   o  There's also documentation for the file format on tsx-11
  813.      <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/ELF.doc.tar.gz>.  This
  814.      is probably of most use to people who want to understand, debug or
  815.      rewrite programs that deal directly with binary objects.
  816.  
  817.   o  H J Lu's document ELF: From The Programmer's Perspective
  818.      <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/elf.latex.tar.gz>
  819.      contains much useful and more detailed information on programming
  820.      with ELF.  If you aren't LaTeX-capable, it is also available as
  821.      PostScript.
  822.  
  823.   o  There is a manual page for dlopen(3) supplied with the ld.so
  824.      package.
  825.  
  826.  
  827.   6.  Legalese
  828.  
  829.   All trademarks used in this document are acknowledged as being owned
  830.   by their respective owners.  (Spot the teeth-gritting irony there...)
  831.  
  832.  
  833.   The right of Daniel Barlow to be identified as the author of this work
  834.   has been asserted in accordance with sections 77 and 78 of the
  835.   Copyright Designs and Patents Act 1988.  (Proof by assertion
  836.  
  837.   This document is copyright (C) 1995 Daniel Barlow
  838.   <daniel.barlow@sjc.ox.ac.uk> It may be reproduced and distributed in
  839.   whole or in part, in any medium physical or electronic, as long as
  840.   this copyright notice is retained on all copies. Commercial
  841.   redistribution is allowed and encouraged; however, the author would
  842.   like to be notified of any such distributions.
  843.  
  844.   All translations, derivative works, or aggregate works incorporating
  845.   any Linux HOWTO documents must be covered under this copyright notice.
  846.   That is, you may not produce a derivative work from a HOWTO and impose
  847.   additional restrictions on its distribution. Exceptions to these rules
  848.   may be granted under certain conditions; please contact the Linux
  849.   HOWTO coordinator at the address given below.
  850.  
  851.   In short, we wish to promote dissemination of this information through
  852.   as many channels as possible. However, we do wish to retain copyright
  853.   on the HOWTO documents, and would like to be notified of any plans to
  854.   redistribute the HOWTOs.
  855.  
  856.   If you have questions, please contact Greg Hankins, the Linux HOWTO
  857.   coordinator, at gregh@sunsite.unc.edu via email, or at +1 404 853
  858.   9989.
  859.